home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
win
/
pascal
/
alrmtpw.exe
/
ALARM.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-09-09
|
16KB
|
494 lines
{ File: Alarm.pas }
{ Created: Mon Sep 09 00:25:28 1991 }
{ Description: Main routines for "Alarm" Windows application }
{{ STARTBLOCK File Version Information (REGENERATE) }
{ Regenerated: Mon Sep 09 00:25:28 1991 }
{ Skeleton by: Winpro/3, a product from Louis J. Cutrona, Jr. }
{ tpw.skl version 0.05 }
{{ ENDBLOCK }
program AlarmProgram ;
{$R Alarm.res }
uses
WinDos,
WinTypes,
WinProcs,
Strings,
WObjects,
StdWnds,
AlarRC, AlarGbl, AlarDlg ;
{ A L A R M }
{ A P P L I C A T I O N O B J E C T D E F I N I T I O N }
type
tAlarm = object( TApplication )
constructor Init( lpszName: PChar ) ;
procedure InitInstance ; virtual ;
procedure InitMainWindow ; virtual ;
procedure Run ; virtual ;
end ;
{ A L A R M W I N D O W }
{ M A I N W I N D O W O B J E C T D E F I N I T I O N }
type
tpAlarmWindow = ^tAlarmWindow ;
tAlarmWindow = object( TWindow )
constructor Init( pwoParent: PWindowsObject; lpszTitle: PChar ) ;
destructor Done ; Virtual ;
{ We need a new GetWindowClass to have our own icon and menu }
procedure GetWindowClass( var WndClass: TWndClass ) ; virtual ;
{ We need to override GetClassName because different Windows }
{ applications must use different class names. }
function GetClassName: PChar ; virtual ;
{ One-time initialization after window is created }
procedure SetupWindow; virtual ;
{ We need to handle wm_Timer messages and wm_User messages }
procedure WMTimerMethod( var Msg: TMessage ) ;
virtual wm_First + wm_Timer ;
procedure WMUserMethod( var Msg: TMessage ) ;
virtual wm_First + wm_User ;
{ WM_COMMAND processing methods (menu selections & accelerator keys ) }
procedure dlg_SetAlarmTimeMethod( var Msg: TMessage ) ;
virtual cm_First + dlg_SetAlarmTime ;
procedure idmALARMONMethod( var Msg: TMessage ) ;
virtual cm_First + idmALARMON ;
procedure idmALARMOFFMethod( var Msg: TMessage ) ;
virtual cm_First + idmALARMOFF ;
procedure dlg_AboutAlarmMethod( var Msg: TMessage ) ;
virtual cm_First + dlg_AboutAlarm ;
procedure STDCLOSEMethod( var Msg: TMessage ) ;
virtual cm_First + STDCLOSE ;
procedure idmHIDEMethod( var Msg: TMessage ) ;
virtual cm_First + idmHIDE ;
end ;
{ A L A R M W I N D O W . I N I T }
{{ STARTBLOCK Main window constructor (REGENERATE) }
constructor tAlarmWindow.Init( pwoParent: PWindowsObject; lpszTitle: PChar ) ;
begin
TWindow.Init( pwoParent, lpszTitle ) ;
Attr.Style := ws_Overlapped
or ws_Caption
or ws_SysMenu
or ws_MinimizeBox
or ws_ClipSiblings
(*or ws_Visible*) ;
Attr.X := 140 ;
Attr.Y := 150 ;
Attr.W := 385 ;
Attr.H := 160 ;
end ;
{{ ENDBLOCK }
{ A L A R M W I N D O W . D O N E }
{ Main window destructor }
destructor tAlarmWindow.Done ;
begin
{ Do here any cleanup required when the main window closes }
if gbl_cAlarmSet = 'Y' then
KillTimer( hWindow, 1 ) ;
{ Then, call standard cleanup }
TWindow.Done ;
end ;
{ A L A R M W I N D O W . G E T W I N D O W C L A S S }
{ Modify default window object characteristics }
procedure tAlarmWindow.GetWindowClass( var WndClass: TWndClass ) ;
begin
{ Let TWindow set the defaults }
TWindow.GetWindowClass( WndClass ) ;
{{ STARTBLOCK Override TWindow window class defaults (REGENERATE) }
WndClass.hIcon := LoadIcon( hInstance, PChar( ALARM_ICON ) ) ;
WndClass.lpszMenuName := PChar( ALARM_MENU ) ;
WndClass.hbrBackground := color_Window + 1 ;
{{ ENDBLOCK }
end ;
{ A L A R M W I N D O W . G E T C L A S S N A M E }
function tAlarmWindow.GetClassName: PChar;
begin
GetClassName := 'Alarm' ;
end;
{ Correct execution of the SetupWindow procedure defined below requires }
{ short-circuit boolean evaluation. Although this is the default, it }
{ may have been overridden through settings in the Options|Compiler }
{ menu. The next line turns short-circuit evaluation on as insurance. }
{$B-}
procedure tAlarmWindow.SetupWindow;
var
bCancel: Bool ;
hmenuPopup: HMenu ;
p: PChar ;
begin
if gbl_cAlarmSet = 'Y' then
begin
{ We want a timer. See if one is available. If not, give user }
{ the option of cancelling or retrying after shutting down }
{ something else that uses a timer. }
bCancel := False ;
while not bCancel and not Bool( SetTimer( hWindow, 1, 30000, nil ) ) do
if idCancel = MessageBox( hWindow,
'Sorry, no more clocks or timers available.',
'Alarm Can''t Run',
mb_RetryCancel or mb_IconExclamation ) then
bCancel := True ;
if bCancel then
CloseWindow ;
{ We got a timer, so check the 'On' menu item and uncheck 'Off' }
hmenuPopup := GetSubMenu( GetMenu( hWindow ), 0 ) ;
CheckMenuItem( hmenuPopup, idmALARMON, mf_ByCommand or mf_Checked ) ;
CheckMenuItem( hmenuPopup, idmALARMOFF, mf_ByCommand or mf_Unchecked ) ;
end;
{ See if the user specified /s -s /S or -S on the command line and }
{ if so, leave the window visible. }
if ( StrPos( CmdLine, '/s' ) = nil )
and ( StrPos( CmdLine, '-s' ) = nil )
and ( StrPos( CmdLine, '/S' ) = nil )
and ( StrPos( CmdLine, '-S' ) = nil ) then
CmdShow := sw_Hide ;
end;
procedure tAlarmWindow.WMTimerMethod( var Msg: TMessage ) ;
var
wDayOfWeek: Word ;
wSecond: Word ;
wSec100: Word ;
begin
GetDate( gbl_wYearNow, gbl_wMonthNow, gbl_wDayNow, wDayOfWeek ) ;
gbl_wMonthNow := gbl_wMonthNow - 1900 ;
GetTime( gbl_wHourNow, gbl_wMinuteNow, wSecond, wSec100 ) ;
if ( gbl_wYearNow < gbl_wYearAlarm )
or ( gbl_wMonthNow < gbl_wMonthAlarm )
or ( gbl_wDayNow < gbl_wDayAlarm )
or ( gbl_wHourNow < gbl_wHourAlarm )
or ( gbl_wMinuteNow < gbl_wMinuteAlarm ) then
begin
{ Too early. Wait a minute }
SetTimer( hWindow, 1, 30000, nil ) ;
end
else
begin
{ Now! }
KillTimer( hWindow, 1 ) ;
gbl_cAlarmSet := 'N' ;
SendMessage( hWindow, wm_Command, idmALARMOFF, 0 ) ;
MessageBeep( 0 ) ;
MessageBox( hWindow,
dlg_SetAlarmTimeTransferBuf.szEM_MESSAGE,
'Ding-a-Ling',
mb_OK or mb_IconAsterisk ) ;
end ;
end ;
procedure tAlarmWindow.WMUserMethod( var Msg: TMessage ) ;
begin
{ If window is hidden, make it visible. Otherwise, ignore }
MessageBeep( 0 ) ;
if not IsWindowVisible( hWindow ) then
begin
Show( sw_ShowNormal ) ;
BringWindowToTop( hWindow ) ;
end ;
end ;
{ AlarmWindow -- WM_COMMAND processing methods }
{ (menu selections & accelerator keys ) }
{{ STARTBLOCK Main window menu/accelerator selection dlg_SetAlarmTime (REGENERATE) }
procedure tAlarmWindow.dlg_SetAlarmTimeMethod( var Msg: TMessage ) ;
var
RetCode: Integer ;
pdlg_SetAlarmTimeDialog: tpdlg_SetAlarmTimeDialog ;
szBuf: Array[0..11] of Char ;
i: Integer ;
begin
pdlg_SetAlarmTimeDialog := New( tpdlg_SetAlarmTimeDialog, Init( @Self, PChar( dlg_SetAlarmTime ) ) ) ;
RetCode := Application^.ExecDialog( pdlg_SetAlarmTimeDialog ) ;
if RetCode = id_OK then
begin
{ User selected OK pushbutton or equivalent. }
{ Updated dialog data are in dlg_SetAlarmTimeTransferBuf. }
{ Translate into numbers }
with dlg_SetAlarmTimeTransferBuf do
begin
{ In a more fully developed example, each of these values }
{ would be error-checked. }
Val( PChar( @szET_YEAR[0] ), gbl_wYearAlarm, RetCode ) ;
Str( gbl_wYearAlarm:2, szET_YEAR ) ;
Val( PChar( @szET_MONTH[0] ), gbl_wMonthAlarm, RetCode ) ;
Str( gbl_wMonthAlarm:2, szET_MONTH ) ;
Val( PChar( @szET_DAY[0] ), gbl_wDayAlarm, RetCode ) ;
Str( gbl_wDayAlarm:2, szET_DAY ) ;
Val( PChar( @szET_HOUR[0] ), gbl_w